﻿namespace Unity.Graphs.LogicGraph
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using UnityEditor;
    using UnityEngine;

    public class CodeGenGraphUtils
    {
        [CompilerGenerated]
        private static Func<Assembly, bool> <>f__am$cache0;
        [CompilerGenerated]
        private static Func<Assembly, bool> <>f__am$cache1;
        [CompilerGenerated]
        private static Func<Assembly, bool> <>f__am$cache2;
        [CompilerGenerated]
        private static Func<Assembly, bool> <>f__am$cache3;
        [CompilerGenerated]
        private static Func<string, bool> <>f__am$cache4;
        [CompilerGenerated]
        private static Func<AssemblyName, bool> <>f__am$cache5;
        [CompilerGenerated]
        private static Func<AssemblyName, bool> <>f__am$cache6;

        internal static System.Type FindTypeInPlayerAssemblies(string Name)
        {
            System.Type type = System.Type.GetType(Name);
            if (type != null)
            {
                return type;
            }
            string name = !Name.Contains<char>(',') ? Name : Name.Substring(0, Name.IndexOf(','));
            IEnumerator<Assembly> enumerator = GetEngineAndPlayerAssemblies().GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    type = enumerator.Current.GetType(name);
                    if (type != null)
                    {
                        return type;
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
            throw new ArgumentException("Failed to find type " + Name);
        }

        [DebuggerHidden]
        public static IEnumerable<Assembly> GetEditorAndPlayerAssemblies()
        {
            return new <GetEditorAndPlayerAssemblies>c__Iterator2 { $PC = -2 };
        }

        [DebuggerHidden]
        public static IEnumerable<Assembly> GetEditorAndUserEditorAssemblies()
        {
            return new <GetEditorAndUserEditorAssemblies>c__Iterator3 { $PC = -2 };
        }

        [DebuggerHidden]
        public static IEnumerable<Assembly> GetEngineAndPlayerAssemblies()
        {
            return new <GetEngineAndPlayerAssemblies>c__Iterator1 { $PC = -2 };
        }

        internal static string GetEngineAssemblyPath()
        {
            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                return (Path.GetDirectoryName(EditorApplication.applicationPath) + "/Data/Managed/UnityEngine.dll");
            }
            return (EditorApplication.applicationPath + "/Contents/Frameworks/Managed/UnityEngine.dll");
        }

        internal static string GetNodeLibraryPath()
        {
            return (EditorApplication.applicationContentsPath + "/Managed/Unity.Graphs.LogicGraph.dll");
        }

        public static IEnumerable<Assembly> GetPlayerAssemblies()
        {
            if (<>f__am$cache0 == null)
            {
                <>f__am$cache0 = asm => asm.GetName().Name.Length == 0x20;
            }
            if (<>f__am$cache1 == null)
            {
                <>f__am$cache1 = delegate (Assembly asm) {
                    if (<>f__am$cache5 == null)
                    {
                        <>f__am$cache5 = Name => Name.Name == "UnityEditor";
                    }
                    return !Enumerable.Any<AssemblyName>(asm.GetReferencedAssemblies(), <>f__am$cache5);
                };
            }
            return Enumerable.Where<Assembly>(Enumerable.Where<Assembly>(AppDomain.CurrentDomain.GetAssemblies(), <>f__am$cache0), <>f__am$cache1);
        }

        internal static IEnumerable<string> GetPlayerAssemblyPaths()
        {
            if (<>f__am$cache4 == null)
            {
                <>f__am$cache4 = file => !file.Contains("Editor");
            }
            return Enumerable.Where<string>(Directory.GetFiles("Library/ScriptAssemblies", "Assembly*.dll"), <>f__am$cache4);
        }

        public static IEnumerable<Assembly> GetUserEditorAssemblies()
        {
            if (<>f__am$cache2 == null)
            {
                <>f__am$cache2 = asm => asm.GetName().Name.Length == 0x20;
            }
            if (<>f__am$cache3 == null)
            {
                <>f__am$cache3 = delegate (Assembly asm) {
                    if (<>f__am$cache6 == null)
                    {
                        <>f__am$cache6 = Name => Name.Name == "UnityEditor";
                    }
                    return Enumerable.Any<AssemblyName>(asm.GetReferencedAssemblies(), <>f__am$cache6);
                };
            }
            return Enumerable.Where<Assembly>(Enumerable.Where<Assembly>(AppDomain.CurrentDomain.GetAssemblies(), <>f__am$cache2), <>f__am$cache3);
        }

        [CompilerGenerated]
        private sealed class <GetEditorAndPlayerAssemblies>c__Iterator2 : IEnumerator, IDisposable, IEnumerable<Assembly>, IEnumerator<Assembly>, IEnumerable
        {
            internal Assembly $current;
            internal int $PC;
            internal IEnumerator<Assembly> <$s_124>__0;
            internal Assembly[] <$s_125>__2;
            internal int <$s_126>__3;
            internal Assembly <asm>__1;
            internal Assembly <asm>__4;

            [DebuggerHidden]
            public void Dispose()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                switch (num)
                {
                    case 1:
                        try
                        {
                        }
                        finally
                        {
                            if (this.<$s_124>__0 == null)
                            {
                            }
                            this.<$s_124>__0.Dispose();
                        }
                        break;
                }
            }

            public bool MoveNext()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                bool flag = false;
                switch (num)
                {
                    case 0:
                        this.<$s_124>__0 = CodeGenGraphUtils.GetPlayerAssemblies().GetEnumerator();
                        num = 0xfffffffd;
                        break;

                    case 1:
                        break;

                    case 2:
                        goto Label_0130;

                    default:
                        goto Label_0137;
                }
                try
                {
                    while (this.<$s_124>__0.MoveNext())
                    {
                        this.<asm>__1 = this.<$s_124>__0.Current;
                        this.$current = this.<asm>__1;
                        this.$PC = 1;
                        flag = true;
                        goto Label_0139;
                    }
                }
                finally
                {
                    if (!flag)
                    {
                    }
                    if (this.<$s_124>__0 == null)
                    {
                    }
                    this.<$s_124>__0.Dispose();
                }
                this.<$s_125>__2 = AppDomain.CurrentDomain.GetAssemblies();
                this.<$s_126>__3 = 0;
                while (this.<$s_126>__3 < this.<$s_125>__2.Length)
                {
                    this.<asm>__4 = this.<$s_125>__2[this.<$s_126>__3];
                    if (this.<asm>__4.GetName().Name == "Unity.Graphs.LogicGraph.Editor")
                    {
                        this.$current = this.<asm>__4;
                        this.$PC = 2;
                        goto Label_0139;
                    }
                    this.<$s_126>__3++;
                }
            Label_0130:
                this.$PC = -1;
            Label_0137:
                return false;
            Label_0139:
                return true;
            }

            [DebuggerHidden]
            public void Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<Assembly> IEnumerable<Assembly>.GetEnumerator()
            {
                if (Interlocked.CompareExchange(ref this.$PC, 0, -2) == -2)
                {
                    return this;
                }
                return new CodeGenGraphUtils.<GetEditorAndPlayerAssemblies>c__Iterator2();
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return this.System.Collections.Generic.IEnumerable<System.Reflection.Assembly>.GetEnumerator();
            }

            Assembly IEnumerator<Assembly>.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }
        }

        [CompilerGenerated]
        private sealed class <GetEditorAndUserEditorAssemblies>c__Iterator3 : IEnumerator, IDisposable, IEnumerable<Assembly>, IEnumerator<Assembly>, IEnumerable
        {
            internal Assembly $current;
            internal int $PC;
            internal IEnumerator<Assembly> <$s_127>__0;
            internal Assembly[] <$s_128>__2;
            internal int <$s_129>__3;
            internal Assembly <asm>__1;
            internal Assembly <asm>__4;

            [DebuggerHidden]
            public void Dispose()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                switch (num)
                {
                    case 1:
                        try
                        {
                        }
                        finally
                        {
                            if (this.<$s_127>__0 == null)
                            {
                            }
                            this.<$s_127>__0.Dispose();
                        }
                        break;
                }
            }

            public bool MoveNext()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                bool flag = false;
                switch (num)
                {
                    case 0:
                        this.<$s_127>__0 = CodeGenGraphUtils.GetUserEditorAssemblies().GetEnumerator();
                        num = 0xfffffffd;
                        break;

                    case 1:
                        break;

                    case 2:
                        goto Label_0130;

                    default:
                        goto Label_0137;
                }
                try
                {
                    while (this.<$s_127>__0.MoveNext())
                    {
                        this.<asm>__1 = this.<$s_127>__0.Current;
                        this.$current = this.<asm>__1;
                        this.$PC = 1;
                        flag = true;
                        goto Label_0139;
                    }
                }
                finally
                {
                    if (!flag)
                    {
                    }
                    if (this.<$s_127>__0 == null)
                    {
                    }
                    this.<$s_127>__0.Dispose();
                }
                this.<$s_128>__2 = AppDomain.CurrentDomain.GetAssemblies();
                this.<$s_129>__3 = 0;
                while (this.<$s_129>__3 < this.<$s_128>__2.Length)
                {
                    this.<asm>__4 = this.<$s_128>__2[this.<$s_129>__3];
                    if (this.<asm>__4.GetName().Name == "Unity.Graphs.LogicGraph.Editor")
                    {
                        this.$current = this.<asm>__4;
                        this.$PC = 2;
                        goto Label_0139;
                    }
                    this.<$s_129>__3++;
                }
            Label_0130:
                this.$PC = -1;
            Label_0137:
                return false;
            Label_0139:
                return true;
            }

            [DebuggerHidden]
            public void Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<Assembly> IEnumerable<Assembly>.GetEnumerator()
            {
                if (Interlocked.CompareExchange(ref this.$PC, 0, -2) == -2)
                {
                    return this;
                }
                return new CodeGenGraphUtils.<GetEditorAndUserEditorAssemblies>c__Iterator3();
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return this.System.Collections.Generic.IEnumerable<System.Reflection.Assembly>.GetEnumerator();
            }

            Assembly IEnumerator<Assembly>.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }
        }

        [CompilerGenerated]
        private sealed class <GetEngineAndPlayerAssemblies>c__Iterator1 : IEnumerator, IDisposable, IEnumerable<Assembly>, IEnumerator<Assembly>, IEnumerable
        {
            internal Assembly $current;
            internal int $PC;
            internal IEnumerator<Assembly> <$s_121>__0;
            internal Assembly[] <$s_122>__2;
            internal int <$s_123>__3;
            internal Assembly <asm>__1;
            internal Assembly <asm>__4;

            [DebuggerHidden]
            public void Dispose()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                switch (num)
                {
                    case 1:
                        try
                        {
                        }
                        finally
                        {
                            if (this.<$s_121>__0 == null)
                            {
                            }
                            this.<$s_121>__0.Dispose();
                        }
                        break;
                }
            }

            public bool MoveNext()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                bool flag = false;
                switch (num)
                {
                    case 0:
                        this.<$s_121>__0 = CodeGenGraphUtils.GetPlayerAssemblies().GetEnumerator();
                        num = 0xfffffffd;
                        break;

                    case 1:
                        break;

                    case 2:
                        goto Label_0130;

                    default:
                        goto Label_0137;
                }
                try
                {
                    while (this.<$s_121>__0.MoveNext())
                    {
                        this.<asm>__1 = this.<$s_121>__0.Current;
                        this.$current = this.<asm>__1;
                        this.$PC = 1;
                        flag = true;
                        goto Label_0139;
                    }
                }
                finally
                {
                    if (!flag)
                    {
                    }
                    if (this.<$s_121>__0 == null)
                    {
                    }
                    this.<$s_121>__0.Dispose();
                }
                this.<$s_122>__2 = AppDomain.CurrentDomain.GetAssemblies();
                this.<$s_123>__3 = 0;
                while (this.<$s_123>__3 < this.<$s_122>__2.Length)
                {
                    this.<asm>__4 = this.<$s_122>__2[this.<$s_123>__3];
                    if (this.<asm>__4.GetName().Name == "Unity.Graphs.LogicGraph")
                    {
                        this.$current = this.<asm>__4;
                        this.$PC = 2;
                        goto Label_0139;
                    }
                    this.<$s_123>__3++;
                }
            Label_0130:
                this.$PC = -1;
            Label_0137:
                return false;
            Label_0139:
                return true;
            }

            [DebuggerHidden]
            public void Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<Assembly> IEnumerable<Assembly>.GetEnumerator()
            {
                if (Interlocked.CompareExchange(ref this.$PC, 0, -2) == -2)
                {
                    return this;
                }
                return new CodeGenGraphUtils.<GetEngineAndPlayerAssemblies>c__Iterator1();
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return this.System.Collections.Generic.IEnumerable<System.Reflection.Assembly>.GetEnumerator();
            }

            Assembly IEnumerator<Assembly>.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }
        }
    }
}

